﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WordGame.Question;

namespace WordGame.Answer
{
    class Effie : IWordGame
    {
        private bool FitRule(string cur, string pre)
        {

            if (cur.Length != pre.Length + 1)

                return false;

            return cur.Substring(1) == pre || cur.Substring(0, cur.Length - 1) == pre;

        }



        public int getCheater(string[] first, string[] second, string[] third)
        {


            string[][] game = { first, second, third };

            int cnt = 1;

            string pre = first[0];

            while (true)
            {

                int row = cnt % 3;

                int col = cnt / 3;

                if (col >= game[row].Length)

                    return -1;

                string cur = game[row][col];

                if (FitRule(cur, pre))
                {
                    pre = cur;

                }

                else
                {  
                    return (cnt - 1) % 3 + 1;
                }

                ++cnt;

            }
        }
    }
}

